/**
 * website runtime basic template
 * 
 * import by astro layout
 */

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/service-worker.js').then(registration => {
      // 检查是否是PWA环境
      if (window.matchMedia('(display-mode: standalone)').matches) {
        // 发送消息至Service Worker，以缓存所有资源
        registration.active?.postMessage({ type: 'CACHE_ALL' });
      }
    });
  });
}